<template>
  <!-- 接站补全信息 -->
  <div class="JNPF-common-layout" style="min-height: 650px;">
    <div class="JNPF-preview-main">

      <el-row :gutter="15" class=" main" :style="{margin: '0 auto',width: '100%'}">
        <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="100px" label-position="right">
          <template v-if="!loading">
            <el-col :span="24">
              <el-form-item label="流程标题" prop="title">
                <el-input :disabled="pageType=='detail'" v-model="dataForm.title" placeholder="请输入" clearable :style='{"width":"100%"}'>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="所属接待任务" prop="taskcontent">
                <el-input :disabled="pageType=='detail'" v-model="dataForm.taskcontent" placeholder="请输入" clearable :style='{"width":"100%"}'>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="所属部门" prop="deptid">
                <dep-select :disabled="pageType=='detail'" v-model="dataForm.deptid" placeholder="请选择" clearable>

                </dep-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="司机电话" prop="mobilenum">
                <JNPFTreeSelect :disabled="pageType=='detail'" v-model="dataForm.mobilenum" placeholder="请选择" clearable :options="mobilenumOptions"
                  :props="mobilenumProps">

                </JNPFTreeSelect>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="车牌号" prop="carnum">
                <el-input :disabled="pageType=='detail'" v-model="dataForm.carnum" placeholder="请输入" clearable :style='{"width":"100%"}'>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="使用车型" prop="cartyp">
                <JNPFTreeSelect :disabled="pageType=='detail'" v-model="dataForm.cartyp" placeholder="请选择" clearable :options="cartypOptions"
                  :props="cartypProps">

                </JNPFTreeSelect>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="公里数" prop="kilometers">
                <el-input-number :disabled="pageType=='detail'" v-model="dataForm.kilometers" placeholder="数字文本" :step="1">

                </el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="开始日期" prop="startdte">
                <el-date-picker :disabled="pageType=='detail'" v-model="dataForm.startdte" placeholder="请选择" clearable :style='{"width":"100%"}'
                  type="date" format="yyyy-MM-dd" value-format="timestamp">

                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="结束日期" prop="enddte">
                <el-date-picker :disabled="pageType=='detail'" v-model="dataForm.enddte" placeholder="请选择" clearable :style='{"width":"100%"}'
                  type="date" format="yyyy-MM-dd" value-format="timestamp">

                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="车次号/航班号" prop="flightnum">
                <el-input :disabled="pageType=='detail'" v-model="dataForm.flightnum" placeholder="请输入" clearable :style='{"width":"100%"}'>

                </el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="到达地点" prop="aress">
                <el-input :disabled="pageType=='detail'" v-model="dataForm.aress" placeholder="请输入" clearable :style='{"width":"100%"}'>

                </el-input>
              </el-form-item>
            </el-col>
          </template>
          <div class="JNPF-common-page-header" style="border: none;">
            <div class="options">
              <el-button @click="goBack">关闭</el-button>
              <el-button v-if="pageType!='detail'" type="primary" @click="dataFormSubmit()"> 保 存</el-button>
            </div>
          </div>
        </el-form>
      </el-row>
    </div>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import {
    getDictionaryDataSelector
  } from '@/api/systemData/dictionary'
  import {
    getDataInterfaceRes
  } from '@/api/systemData/dataInterface'

  export default {
    components: {},
    props: [],
    data() {
      return {
        loading: false,
        dataForm: {
          planid: '',
          title: '',
          taskcontent: '',
          deptid: '',
          mobilenum: "",
          carnum: '',
          cartyp: "",
          kilometers: '',
          startdte: '',
          enddte: '',
          flightnum: '',
          aress: '',
        },

        rules: {},
        mobilenumOptions: [],
        mobilenumProps: {
          "children": "children",
          "label": "fullName",
          "value": "id"
        },
        cartypOptions: [],
        cartypProps: {
          "children": "children",
          "label": "fullName",
          "value": "id"
        },
        pageData: null,
        pageType:''
      }
    },
    computed: {},
    watch: {},
    created() {
      this.getmobilenumOptions();
      this.getcartypOptions();
    },
    mounted() {},
    methods: {
      getmobilenumOptions() {
        getDictionaryDataSelector('424618472031395973').then(res => {
          this.mobilenumOptions = res.data.list
        })
      },
      getcartypOptions() {
        getDictionaryDataSelector('424618614683869317').then(res => {
          this.cartypOptions = res.data.list
        })
      },
      goBack() {
        this.$emit('refresh')
      },
      init(row,type) {
        this.dataForm.planid = row.id;
        this.pageData = row
        this.pageType=type;
        request({
          url: `/api/example/BusReceivePlanJiezhan/detail/${row.id}`,
          method: 'get',
        }).then((res) => {
          if (res.code == 200 && res.data) {
            this.dataForm = res.data;
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            var _data = this.dataList()
            if (this.pageData.taskcount == 1) {
              // 编辑
              request({
                url: `/api/example/BusReceivePlanJiezhan/${this.dataForm.id}`,
                method: 'put',
                data: _data
              }).then((res) => {
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.$emit('refresh', true)
                  }
                })
              })
            } else {
              // 添加
              request({
                url: `/api/example/BusReceivePlanJiezhan`,
                method: 'post',
                data: _data
              }).then((res) => {
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () => {
                    this.$emit('refresh', true)
                  }
                })
              })
            }

          }
        })
      },
      resetForm() {
        this.$refs['elForm'].resetFields()
        this.init()
      },
      dataList() {
        var _data = JSON.parse(JSON.stringify(this.dataForm));
        return _data;
      },
      dataInfo(dataAll) {
        let _dataAll = dataAll
        this.dataForm = _dataAll
      },
    },
  }

</script>
